#include "i2c.h"

void I2C_initController(uint32_t base, uint32_t sysclkHz, uint32_t bitRate)
{ }

//*****************************************************************************
//
// I2C_enableInterrupt
//
//*****************************************************************************
void I2C_enableInterrupt(uint32_t base, uint32_t intFlags)
{
    //
    // Check the arguments.
    //
    ASSERT(I2C_isBaseValid(base));

    //
    // Enable the desired basic interrupts
    //
    HWREG(base + I2C_O_INTR_MASK) |= (intFlags & 0xFFFFU);
}

//*****************************************************************************
//
// I2C_disableInterrupt
//
//*****************************************************************************
void I2C_disableInterrupt(uint32_t base, uint32_t intFlags)
{
    //
    // Check the arguments.
    //
    ASSERT(I2C_isBaseValid(base));

    //
    // Disable the desired basic interrupts.
    //
    HWREG(base + I2C_O_INTR_MASK) &= ~(intFlags & 0xFFFFU);
}

//*****************************************************************************
//
// I2C_getInterruptStatus
//
//*****************************************************************************
uint32_t I2C_getInterruptStatus(uint32_t base)
{
    //
    // Check the arguments.
    //
    ASSERT(I2C_isBaseValid(base));

    return (HWREG(base + I2C_O_INTR_STAT));
}

//*****************************************************************************
//
// I2C_clearInterruptStatus
//
//*****************************************************************************
void I2C_clearInterruptStatus(uint32_t base, uint32_t intFlags)
{
    uint32_t tmp;

    //
    // Check the arguments.
    //
    ASSERT(I2C_isBaseValid(base));

    //
    // Clear the interrupt flags that are located in STR.
    //
    switch (intFlags)
    {
        case I2C_INT_NONE:
            break;
        case I2C_INT_RX_UNDER:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_RX_UNDER);
            break;
        case I2C_INT_RX_OVER:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_RX_OVER);
            break;
        case I2C_INT_RX_FULL:
            break;
        case I2C_INT_TX_OVER:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_TX_OVER);
            break;
        case I2C_INT_TX_EMPTY:
            break;
        case I2C_INT_RD_REQ:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_RD_REQ);
            break;
        case I2C_INT_TX_ABORT:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_TX_ABRT);
            break;
        case I2C_INT_RX_DONE:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_RX_DONE);
            break;
        case I2C_INT_ACTIVITY:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_ACTIVITY);
            break;
        case I2C_INT_STOP_CONDITION:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_STOP_DET);
            break;
        case I2C_INT_START_DET:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_START_DET);
            break;
        case I2C_INT_GEN_CALL:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_GEN_CALL);
            break;
        case I2C_INT_ALL:
            tmp = (uint32_t)HWREG(base + I2C_O_CLR_INTR);
            break;
    }
}
